home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / python2.4 / test / test_signal.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2005-10-18  |  2KB  |  75 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.4)
  3.  
  4. from test.test_support import verbose, TestSkipped, TestFailed
  5. import signal
  6. import os
  7. import sys
  8. import time
  9. if sys.platform[:3] in ('win', 'os2') or sys.platform == 'riscos':
  10.     raise TestSkipped, "Can't test signal on %s" % sys.platform
  11.  
  12. if verbose:
  13.     x = '-x'
  14. else:
  15.     x = '+x'
  16. pid = os.getpid()
  17. script = '\n (\n        set %(x)s\n        sleep 2\n        kill -HUP %(pid)d\n        sleep 2\n        kill -USR1 %(pid)d\n        sleep 2\n        kill -USR2 %(pid)d\n ) &\n' % vars()
  18.  
  19. def handlerA(*args):
  20.     if verbose:
  21.         print 'handlerA', args
  22.     
  23.  
  24.  
  25. class HandlerBCalled(Exception):
  26.     pass
  27.  
  28.  
  29. def handlerB(*args):
  30.     if verbose:
  31.         print 'handlerB', args
  32.     
  33.     raise HandlerBCalled, args
  34.  
  35. signal.alarm(20)
  36. hup = signal.signal(signal.SIGHUP, handlerA)
  37. usr1 = signal.signal(signal.SIGUSR1, handlerB)
  38. usr2 = signal.signal(signal.SIGUSR2, signal.SIG_IGN)
  39. alrm = signal.signal(signal.SIGALRM, signal.default_int_handler)
  40.  
  41. try:
  42.     os.system(script)
  43.     print 'starting pause() loop...'
  44.     
  45.     try:
  46.         while verbose:
  47.             print 'call pause()...'
  48.         
  49.         try:
  50.             signal.pause()
  51.             if verbose:
  52.                 print 'pause() returned'
  53.         continue
  54.         except HandlerBCalled:
  55.             if verbose:
  56.                 print 'HandlerBCalled exception caught'
  57.             
  58.             verbose
  59.         
  60.  
  61.         None<EXCEPTION MATCH>HandlerBCalled
  62.     except KeyboardInterrupt:
  63.         if verbose:
  64.             print 'KeyboardInterrupt (assume the alarm() went off)'
  65.         
  66.     except:
  67.         verbose
  68.  
  69. finally:
  70.     signal.signal(signal.SIGHUP, hup)
  71.     signal.signal(signal.SIGUSR1, usr1)
  72.     signal.signal(signal.SIGUSR2, usr2)
  73.     signal.signal(signal.SIGALRM, alrm)
  74.  
  75.